package domain;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.File;

import javax.swing.JPanel;

public class Vierkant extends JPanel{
	Geotop geotop;
	LayerProperty property;
	public Vierkant(File meta, String rafName, File properties){
		this.geotop = new Geotop(meta, rafName);
		this.property = new LayerProperty(properties, true);
	}
	
	/**
	 * Java graphics counts y positive downwards, 
	 * so take account of height of drawing area and take the z-index negatively.
	 */
	protected void paintComponent(Graphics g){
		super.paintComponent(g);
		Graphics2D g2d = (Graphics2D)g;
		int xCount = geotop.getXCount();
		int yCount = geotop.getYCount();
		int zCount = geotop.getZCount();
		int intAttr = 0;
		int red = 0;
		float NoDataValue = geotop.getNoDataValue();
		float[][] plane = geotop.getZPlaneSelectedAttribute(9, xCount, yCount, 0);
		Color color = null;
		for (int i=0; i < xCount; i++){
			for( int j = 0; j < yCount; j++){
				float attribute = plane[i][j];
				System.out.println("Waarde attribute " + i + " " + j + " " + attribute);
				if (attribute != NoDataValue){
					intAttr = (int)Math.round(attribute);
					//color = LayerProperty.colorsP.get(intAttr);	// oud, voldoet niet als ongelijk aan layer indices;
					if(intAttr > 0){
						red = (30 * Math.abs(intAttr - 15))%255;
						color = new Color(red,0,0);
					}
					else{
						color = new Color(0,0,50);
					}	
				}
				else{
					color = Color.DARK_GRAY;
				}
				g2d.setColor(color);
				g2d.fillRect(i*2, 400 - j*2, 2, 2);
			}
		}
	}
}
